package api

import (
	"net/http"
	"strconv"

	"gitee.com/zatto/project/tree/master/vblog/api/apps/tag"
	"github.com/gin-gonic/gin"
)

func (h *handler) CreateTag(c *gin.Context) {
	req := tag.NewDefaultCreateTagRequest()
	if err := c.BindJSON(req); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"msg": err.Error()})
		return
	}
	ins, err := h.svc.CreateTag(c.Request.Context(), req)
	if err != nil {
		c.JSON(http.StatusInternalServerError, gin.H{"msg": err.Error()})
		return
	}
	c.JSON(http.StatusOK, ins)
}

func (h *handler) RemoveTag(c *gin.Context) {
	StrblogId := c.Param("blog_id")
	id, err := strconv.Atoi(StrblogId)
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"msg": err.Error(),
		})
		return
	}

	req := tag.NewRemoveTagRequest(id)

	set, err := h.svc.RemoveTag(c.Request.Context(), req)
	if err != nil {
		c.JSON(http.StatusInternalServerError, gin.H{
			"msg": err.Error(),
		})
		return
	}

	c.JSON(http.StatusOK, set)
}
